var app = getApp();

const postdata = (params) => {
  wx.request({
    url: app.globalData.host_url + params.url,
    method: "post",
    data: params.data,
    header: {
      'content-type': 'application/json' // 默认值
    },
    success(res) {
      if (params.success) {
        params.success(res.data);
      }
    },
    fail(res) {
      if (params.fail) {
        params.fail(res);
      }
    },
    complete(res) {
      if (params.complete) {
        params.complete(res);
      }
    }
  })
}

const getdata = (params) => {
  wx.request({
    url: app.globalData.host_url + params.url + params.data,
    data: { },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    header: {}, // 设置请求的 header
    success: function (res) {
      // success
      if (params.success) {
        params.success(res.data);
      }
    },
    fail: function (res) {
      // fail
      if (params.fail) {
        params.success(res);
      }
    },
    complete: function (res) {
      // complete
      if (params.complete) {
        params.success(res);
      }
    }
  })
}

export {
  postdata,
  getdata
}